<html>
<head><meta charset="utf-8"><title>Replacing mpsc · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html">Replacing mpsc</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="190303524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190303524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190303524">(Mar 11 2020 at 16:43)</a>:</h4>
<p>Hello. I've heard on-and-off that STD's MPSC implementation is due for replacement. While discussing this with a friend, I remembered that I'd written my own implementation a while ago: <a href="https://github.com/zesterer/flume" target="_blank" title="https://github.com/zesterer/flume">https://github.com/zesterer/flume</a></p>
<p>Advantages include:</p>
<ul>
<li>It beats std's mpsc in almost every benchmark I've thrown at it, often by a large margin. It's also competitive with crossbeam's mpsc.</li>
<li>It uses no <code>unsafe</code>, so it's simple to audit</li>
<li>It has no dependencies (except one that I can easily replace with stuff from <code>std::sync</code>)</li>
<li>It's simple so it compiles very quickly</li>
</ul>
<p>I gather that the intention was to replace mpsc with crossbeam, but I feel that crossbeam isn't particularly suitable as a "simple, general-purpose default" owing to its complexity and frequent use of <code>unsafe</code>, and that my crate might be a suitable alternative with a bit of work to clean it up.</p>
<p>Does anybody have any thoughts?</p>



<a name="190304571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190304571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190304571">(Mar 11 2020 at 16:53)</a>:</h4>
<p>my initial thought is that we might want to deprecate std::mpsc instead of replacing it.</p>



<a name="190304701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190304701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190304701">(Mar 11 2020 at 16:54)</a>:</h4>
<p>Oh? For what reason?</p>



<a name="190305130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190305130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190305130">(Mar 11 2020 at 16:57)</a>:</h4>
<p>Just removing things without replacing them sounds very poor</p>



<a name="190305596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190305596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190305596">(Mar 11 2020 at 17:01)</a>:</h4>
<p>Personally, I think that a channel primitive in std is absolutely essential: Rust prides itself on being great for concurrent programming, and to not have at least a simple channel available in std would be quite detrimental to that reputation.</p>



<a name="190305704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190305704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190305704">(Mar 11 2020 at 17:01)</a>:</h4>
<p>i don't really agree. but also don't really feel like having a grand debate either. the problems with mpsc extend beyond its implementation. others have penned more careful thoughts on this: <a href="https://stjepang.github.io/2019/03/02/new-channels.html" target="_blank" title="https://stjepang.github.io/2019/03/02/new-channels.html">https://stjepang.github.io/2019/03/02/new-channels.html</a></p>



<a name="190305903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190305903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190305903">(Mar 11 2020 at 17:03)</a>:</h4>
<p>Oh, regarding a point raised in that article: Flume's <code>Sender</code> is <code>Sync</code>, unlike <code>std</code>'s <code>mpsc</code>.</p>



<a name="190305935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190305935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190305935">(Mar 11 2020 at 17:03)</a>:</h4>
<blockquote>
<p>I gather that the intention was to replace mpsc with crossbeam, but I feel that crossbeam isn't particularly suitable as a "simple, general-purpose default" owing to its complexity and frequent use of unsafe, and that my crate might be a suitable alternative with a bit of work to clean it up.</p>
</blockquote>
<p>I second this, esp. since crossbeam has had several soundness holes in the past, and probably has them now too, e.g. due to the use of memoffset</p>



<a name="190306066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190306066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190306066">(Mar 11 2020 at 17:04)</a>:</h4>
<p>I also agree that channels feel like a very basic thing you expect from a language, esp. from more functional crowds, e.g. say in Erlang.</p>



<a name="190306140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190306140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190306140">(Mar 11 2020 at 17:05)</a>:</h4>
<p>and given that we already have channels, why not work on improving them rather than deprecating them -- from the discussion so far, it didn't seem like the API boundary itself was so problematic.</p>



<a name="190306264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190306264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190306264">(Mar 11 2020 at 17:06)</a>:</h4>
<p>and even if we deprecate, we must ensure the current implementation is sound</p>



<a name="190306778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190306778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190306778">(Mar 11 2020 at 17:10)</a>:</h4>
<p>I agree: For me, I think that it's clear that compile times have become far and away the biggest (user-facing) problem for Rust: at least, user surveys seem to suggest that. A simpler mpsc implementation will go a long way to improving that, especially as mpsc appears to be prolific throughout the ecosystem.</p>



<a name="190312751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190312751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190312751">(Mar 11 2020 at 18:02)</a>:</h4>
<p>Is there a process for proposed inclusions to std?</p>



<a name="190312994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190312994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190312994">(Mar 11 2020 at 18:04)</a>:</h4>
<p>I think for this scale of a change I would suggest an issue to start off with and try to find someone on libs who agrees that we should replace mpsc with a more complete, better implementation if that's the road we want to go down</p>



<a name="190313050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190313050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190313050">(Mar 11 2020 at 18:05)</a>:</h4>
<p>(I tend to feel that channels are pretty complex no matter where they are if done well, so maybe not having them in std is reasonable)</p>



<a name="190316263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190316263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190316263">(Mar 11 2020 at 18:36)</a>:</h4>
<p>Not having them in std is not really an option though at this point; we have them, at most we can deprecate, but they still must be sound regardless</p>



<a name="190319618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190319618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190319618">(Mar 11 2020 at 19:09)</a>:</h4>
<blockquote>
<p>It beats std's mpsc in almost every benchmark I've thrown at it, often by a large margin. It's also competitive with crossbeam's mpsc.</p>
</blockquote>
<p>I see that you're using <code>spin::Mutex&lt;VecDeque&lt;T&gt;&gt;</code> -- it seems like that could have some bad edge cases, like a <code>send</code> requiring allocation while another thread spins trying to <code>recv</code></p>



<a name="190320057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190320057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190320057">(Mar 11 2020 at 19:13)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> The crate is designed such that it attempts to spin with exponential backoff for a very short period, and then uses a condvar to enter into a scheduler-driven sleep until the mutex is available. In effect, it never hits that "bad edge case".</p>



<a name="190320422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190320422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190320422">(Mar 11 2020 at 19:16)</a>:</h4>
<p>I'm talking about blocking on <code>self.queue.lock()</code> -- unless you mean <code>spin</code> has the backoff?</p>



<a name="190320434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190320434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190320434">(Mar 11 2020 at 19:16)</a>:</h4>
<p>(I don't think it does)</p>



<a name="190320650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190320650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190320650">(Mar 11 2020 at 19:19)</a>:</h4>
<p>I've implementing the backoff within the crate: <code>.recv()</code> Checks the mutex once, then does some spinning and backoff for a few ns, and then finally if the mutex still isn't available it enters into a sleep.</p>



<a name="190321447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190321447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190321447">(Mar 11 2020 at 19:27)</a>:</h4>
<p>I'm not talking about having items available in the channel queue, but lower level:</p>
<ul>
<li><code>send</code> unconditionally acquires the lock, then pushes the value, which could take a while for allocation</li>
<li><code>try_recv</code> unconditionally acquires the same lock, which will spin the CPU until available</li>
</ul>



<a name="190321620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190321620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190321620">(Mar 11 2020 at 19:29)</a>:</h4>
<p>I'll address these issues.</p>



<a name="190321901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190321901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190321901">(Mar 11 2020 at 19:32)</a>:</h4>
<p>anyway, the larger point is that there are benefits <em>and</em> trade-offs in choices like these, which are hard to balance for everyone in <code>std</code></p>



<a name="190322449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190322449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190322449">(Mar 11 2020 at 19:37)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> when has there ever not been benefits and trade-offs in std/language/...? ;)</p>



<a name="190322520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190322520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190322520">(Mar 11 2020 at 19:38)</a>:</h4>
<p>That's fair. Are there any specific use-cases you'd be interested in me trying to benchmark?</p>



<a name="190325037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190325037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190325037">(Mar 11 2020 at 20:02)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> ok fine, but universal truths are still true</p>



<a name="190325131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190325131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190325131">(Mar 11 2020 at 20:04)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> have you tried porting all of crossbeam's benchmarks? e.g. their mpmc seems like it could bottleneck</p>



<a name="190325330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190325330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190325330">(Mar 11 2020 at 20:05)</a>:</h4>
<p>and I'd be interested in scalability too, on many-CPU machines if you can</p>



<a name="190326631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190326631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190326631">(Mar 11 2020 at 20:19)</a>:</h4>
<p>I'll look into that, for sure. I've just done a tonne of refactoring, fixing the issues you mentioned. I'm getting significantly better results now. I'll have a go at porting crossbeam's benchmarks as you say. Right now, I'm testing this on a 4 physical / 8 logical Ryzen 7 machine.</p>



<a name="190328906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190328906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190328906">(Mar 11 2020 at 20:39)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> yes, but I think deciding whether we want a good impl in std is the first question to ask. of course it should be correct, but that's secondary</p>



<a name="190328996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190328996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190328996">(Mar 11 2020 at 20:40)</a>:</h4>
<p>if we were to deprecate I would advocate for replacing with something like Mutex&lt;VecDeque&lt;T&gt;&gt; in fact, simplest possible and still decently good enough for most cases (e.g. low-volume channels)</p>



<a name="190329009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329009">(Mar 11 2020 at 20:40)</a>:</h4>
<p>I don't feel strongly that it needs to be a competitive impl myself; but that it should exist, not be deprecated, and should be correct (and focus on that, even if that makes it somewhat slower)</p>



<a name="190329010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329010">(Mar 11 2020 at 20:40)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="128448">@stjepang</span></p>



<a name="190329053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329053">(Mar 11 2020 at 20:41)</a>:</h4>
<p>in some sense if we're fine with a non-competitive impl, I think the calculus changes: it's much easier to approve a noncompetitive replacement</p>



<a name="190329075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329075">(Mar 11 2020 at 20:41)</a>:</h4>
<p>otoh, there's some question in my mind about channels even being a fundamental building block (unlike, e.g., Mutex, Condvar)</p>



<a name="190329121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329121">(Mar 11 2020 at 20:41)</a>:</h4>
<p>Do they need to be a fundamental building block though?</p>



<a name="190329171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329171">(Mar 11 2020 at 20:42)</a>:</h4>
<p>I think a lot of folks expect channels to be there as an important tool in building stuff</p>



<a name="190329177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329177">(Mar 11 2020 at 20:42)</a>:</h4>
<p>even if they are not fundamental in the "decomposition" sense</p>



<a name="190329368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329368">(Mar 11 2020 at 20:44)</a>:</h4>
<p>I think it's an open question in my mind whether deprecating is worse than replacing with a "slow" (but definitely correct) impl.</p>



<a name="190329456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329456">(Mar 11 2020 at 20:45)</a>:</h4>
<p>How slow are we talking? ;)</p>



<a name="190329490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329490">(Mar 11 2020 at 20:45)</a>:</h4>
<p>I mean, IMO, plenty fast</p>



<a name="190329546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329546">(Mar 11 2020 at 20:46)</a>:</h4>
<p>but I don't think I've ever worked with an application in Rust using channels for something that sends particularly often</p>



<a name="190329587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329587">(Mar 11 2020 at 20:47)</a>:</h4>
<p>(I don't have numbers, but I'd guess roughly in the ballpark of 1000 msgs/second is what you'd get with a Mutex with light contention. I could be wrong.)</p>



<a name="190329741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329741">(Mar 11 2020 at 20:48)</a>:</h4>
<p>Doesn't servo use channels intensively?</p>



<a name="190329758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329758">(Mar 11 2020 at 20:48)</a>:</h4>
<p>So I think the message passing idiom is important to support in the standard library in some manner; it's a convenient form of writing code, and I don't think you should have to use crossbeam for this</p>



<a name="190329765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329765">(Mar 11 2020 at 20:49)</a>:</h4>
<p>I think deprecating mpsc is the wrong move. Just because it isn't the best implementation, doesn't mean it isn't good enough for most people, and having mpsc builtin has been immensely useful.</p>



<a name="190329789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329789">(Mar 11 2020 at 20:49)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I think any heavy user of channels today would presumably not be using mpsc from std, since it's not the best out there performance wise (or usability wise)</p>



<a name="190329824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329824">(Mar 11 2020 at 20:50)</a>:</h4>
<p>it sounded like we could make usability improvements though</p>



<a name="190329875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329875">(Mar 11 2020 at 20:50)</a>:</h4>
<p>I'm not too familiar with mspc from std. Is there a fundamental issue with the current API that would require us to deprecate it?</p>



<a name="190329895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329895">(Mar 11 2020 at 20:50)</a>:</h4>
<p>specialized apps will always want a more specialized impl for things though</p>



<a name="190329917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329917">(Mar 11 2020 at 20:50)</a>:</h4>
<p>If it's just that the implementation is slow, then we should improve/replace the implementation, not deprecate the API.</p>



<a name="190329943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329943">(Mar 11 2020 at 20:51)</a>:</h4>
<p>I know the API is clunky and not very nice, but I have not looked too much at whether we can improve it without breakage</p>



<a name="190329959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329959">(Mar 11 2020 at 20:51)</a>:</h4>
<p>I believe there are correctness concerns wrt. the impl, not just slowness</p>



<a name="190329963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190329963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190329963">(Mar 11 2020 at 20:51)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> It is definitely a worse API in a lot of ways that for example <code>crossbeam</code> isn't.</p>



<a name="190330011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330011">(Mar 11 2020 at 20:51)</a>:</h4>
<p>Like, <code>Vec&lt;T&gt;</code> exists, but <code>SmallVec&lt;[T; N]&gt;</code> is often used for specialized cases as well</p>



<a name="190330071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330071">(Mar 11 2020 at 20:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="126931">centril</span> <a href="#narrow/stream/219381-t-libs/topic/Replacing.20mpsc/near/190329959" title="#narrow/stream/219381-t-libs/topic/Replacing.20mpsc/near/190329959">said</a>:</p>
<blockquote>
<p>I believe there are correctness concerns wrt. the impl, not just slowness</p>
</blockquote>
<p>This is definitely true. e.g. I know Cargo recently replaced channels with Mutex&lt;VecDeque&lt;T&gt;&gt; because we were hitting a deadlock or something like that and didn't want to try to fix it</p>



<a name="190330146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330146">(Mar 11 2020 at 20:53)</a>:</h4>
<p>Well it's not just specialised cases. <code>mpsc::Sender</code> is <code>!Sync</code>. <code>crossbeam_channel::Sender</code> is <code>Sync</code>.</p>



<a name="190330185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330185">(Mar 11 2020 at 20:53)</a>:</h4>
<p>This is big limitation in the API imo.</p>



<a name="190330203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330203">(Mar 11 2020 at 20:53)</a>:</h4>
<p>I think at the very least we should have a mpmc impl in std if we believe channels to be important enough (which is naturally more general than mpsc). To my knowledge, if we don't aim for performance (and I think there's no need to ; as Centril notes any use case that wants to be super performant is likely going to want a more specialized impl for its particular conditions), then a  mpmc impl should be relatively straightforward.</p>



<a name="190330257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330257">(Mar 11 2020 at 20:54)</a>:</h4>
<p><span class="user-mention" data-user-id="219696">@XAMPPRocky</span> it is <code>Send</code>, but not <code>Sync</code></p>



<a name="190330261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330261">(Mar 11 2020 at 20:54)</a>:</h4>
<p>and since putting mpmc inside the existing mpsc impl seems... odd, presumably we'd deprecate and replace</p>



<a name="190330279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330279">(Mar 11 2020 at 20:54)</a>:</h4>
<p>It sounded like the auto trait situation was fixable from what <span class="user-mention" data-user-id="128448">@stjepang</span> said</p>



<a name="190330282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330282">(Mar 11 2020 at 20:54)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> god damn it, yes sorry.</p>



<a name="190330302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330302">(Mar 11 2020 at 20:54)</a>:</h4>
<p>Always mix them up <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="190330325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330325">(Mar 11 2020 at 20:55)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> of course it is? like it's trivially true that you can write a mpmc Send/Sync pieces channel</p>



<a name="190330356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330356">(Mar 11 2020 at 20:55)</a>:</h4>
<p>but to do so would need changes internally, and I don't think we can modify the existing impl -- it's too big and no one knows it well enough to review that change</p>



<a name="190330377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330377">(Mar 11 2020 at 20:55)</a>:</h4>
<p>right but if we replace the impl</p>



<a name="190330406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330406">(Mar 11 2020 at 20:56)</a>:</h4>
<p>This feels similar to the move to replace std's Mutex with parking_lot::Mutex. Basically std::sync::Mutex will end up as a wrapper around parking_lot::Mutex, but with a "worse" API since it is already stable. ("worse" in this case refers to poisoning, which nobody cares about, but that's off-topic)</p>



<a name="190330429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330429">(Mar 11 2020 at 20:56)</a>:</h4>
<p>which I think was one of the proposals</p>



<a name="190330578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330578">(Mar 11 2020 at 20:57)</a>:</h4>
<p>So I believe there's a couple proposals floating around:</p>
<ol>
<li>replace the existing impl with a trivially correct mpmc impl, fixing API warts (lack of Sync, mpsc vs. mpmc, etc.)</li>
<li>replace existing impl with a mpsc impl (fast or slow)</li>
<li>deprecating mpsc module in std, directing people to <a href="http://crates.io" target="_blank" title="http://crates.io">crates.io</a></li>
</ol>



<a name="190330646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330646">(Mar 11 2020 at 20:58)</a>:</h4>
<p>I've just pushed a big refactor of Flume to the repo. I'm getting... bizarrely impressive results. I'm skeptical of the quality of my benchmarks (I've yet to port <code>crossbeam</code>'s), but the benchmarks I have show performance easily on-par with <code>crossbeam</code>. I'm not going to take that at face value without more rugged testing, but still. Just thought I'd mention it.</p>



<a name="190330710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330710">(Mar 11 2020 at 20:59)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> one thing to be super cautious about is that if you're just using a spinlock you'll be 'trivially great' but that doesn't necessarily mean you're actually good</p>



<a name="190330783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330783">(Mar 11 2020 at 20:59)</a>:</h4>
<p>i.e., spinlocks can be horrible under contention but have great latency so lead to misleading results</p>



<a name="190330949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330949">(Mar 11 2020 at 21:00)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> That's true, although I'm not "just" using spinlocks: There is exponential backoff and a condvar-based blocking system to compliment it.</p>



<a name="190330974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190330974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190330974">(Mar 11 2020 at 21:00)</a>:</h4>
<p>sure, yes, I'm not saying there's necessarily a problem :)</p>



<a name="190346483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190346483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190346483">(Mar 12 2020 at 00:22)</a>:</h4>
<p>I've just published a new version of the crate that resolves the problems <span class="user-mention" data-user-id="138448">@cuviper</span> pointed out. The new benchmarks seem promising (although I've not yet ported <code>crossbeam_channel</code>'s benchmarks). The only thing that holds it back from being API-compatible with <code>std</code>'s <code>mpsc</code> is the lack of <code>SyncSender</code>, but I'll be adding that soon.</p>



<a name="190347299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190347299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190347299">(Mar 12 2020 at 00:39)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> fwiw, SyncSender IMO is an API wart, but if you really mean bounded channels, then those are indeed necessary</p>



<a name="190347349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190347349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190347349">(Mar 12 2020 at 00:40)</a>:</h4>
<p>(basically ideally IMO you'd not have a separate type for bounded channels on the sender half)</p>



<a name="190347434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190347434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190347434">(Mar 12 2020 at 00:42)</a>:</h4>
<p>I did some experimental work making the channel bounded by default, but I'm probably going to redo the work since it had a few issues. I'll definitely be avoiding separate types for both. <code>SyncSender</code> can just be a thin wrapper around <code>Sender</code>.</p>



<a name="190347547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190347547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190347547">(Mar 12 2020 at 00:44)</a>:</h4>
<p>Sure, yes, I think the ideal is basically just <code>struct SyncSender(Sender);</code> and forwarding all the 2(?) methods</p>



<a name="190347559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190347559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190347559">(Mar 12 2020 at 00:44)</a>:</h4>
<p>I think due to backwards compat reasons we can't straight up make them aliases anyway in std, but there's no reason for external libraries to make the same mistakes</p>



<a name="190347728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190347728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190347728">(Mar 12 2020 at 00:48)</a>:</h4>
<p>I'd also be in favour of adding a <code>channel</code> module to <code>std::sync</code> (or just <code>std</code>) that exposes the same code but with a much cleaner interface.</p>



<a name="190385705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190385705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190385705">(Mar 12 2020 at 12:55)</a>:</h4>
<p>in my view, the problem with mpsc is that it is mpsc. it's such a strange and specialized primitive with weird cliffs. "oh, you want to have multiple consumers? ah okay, then either go use crossbeam or wrap your single consuming channel in a mutex and share it that way." it's a lot of friction. it's also missing key primitives like <code>select!</code> which crossbeam-channel has. all of these are, IMO, serious deficiencies. there are very few scenarios i can think of where i'd recommend someone use <code>std::sync::mpsc</code> over crossbeam-channel. this is why i brought up deprecation. i think we should either deprecate (or similarish) and leave it to <a href="http://crates.io" target="_blank" title="http://crates.io">crates.io</a>, or more long term, eventually bring crossbeam's mpmc channels into std. although i lean more towards the former.</p>
<p>i am unconvinced by arguments about compile times because this is not generally a criterion we've used when determining whether something should go in std. i'm more swayed by "channels are core primitives that belong in std," but we could say that about a lot of things that aren't in std: random number generation, automatic serialization support, and so on. if channels were things that appeared more frequently in public APIs, then i think i'd find this argument more compelling. but they are usually implementation details that do not require libraries to agree on the same channel implementation.</p>
<p>much of the complexity from the existing mpsc implementation in std, AIUI, was from supporting <code>select!</code>, but that's gone now. <span class="user-mention" data-user-id="243558">@Steven Fackler</span>  <a href="https://github.com/rust-lang/rust/pull/42397#issuecomment-315881774" target="_blank" title="https://github.com/rust-lang/rust/pull/42397#issuecomment-315881774">noted this a while back</a>. it seems to me like just replacing the existing implementation with something simpler now that <code>select!</code> is gone is probably fine. it seems reasonable to treat that as orthogonal from the deprecation question. i think the most important bits there are 1) ensuring all semantics remain the same such that there are no breaking changes and 2) performance is roughly competitive, particularly under contention. IIRC, crossbeam-channel has some good benchmarking here. cc <span class="user-mention" data-user-id="128448">@stjepang</span></p>



<a name="190386846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190386846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190386846">(Mar 12 2020 at 13:07)</a>:</h4>
<p>It is true that some of the current implementation's complexity comes from select! support, but it's also sufficiently embedded without an easy way to pull it apart -- also, there's not really anyone who can review those changes to my knowledge (without re-learning the whole implementation, pretty much). That makes me hesitant to treat "let's fix the current impl" as viable, which means we need something essentially fully new. Maybe that means just deprecating and pointing at <a href="http://crates.io" target="_blank" title="http://crates.io">crates.io</a> for channels -- that's fine with me -- maybe it means deprecating std and replacing with a (relatively) slower and much simpler mutex-based channel abstraction.</p>



<a name="190386911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190386911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190386911">(Mar 12 2020 at 13:07)</a>:</h4>
<p>There are also a couple of longstanding bugs with recv_timeout iirc</p>



<a name="190387067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190387067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190387067">(Mar 12 2020 at 13:09)</a>:</h4>
<p>If the problem is with mpsc rather than mpmc, then we could ostensibly still use most of the same API but reexport it under <code>::channels</code> or something and just deprecate the old path, but not deprecate channels in std overall</p>



<a name="190387120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190387120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190387120">(Mar 12 2020 at 13:09)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> i think we're on the same page?</p>



<a name="190387314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190387314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190387314">(Mar 12 2020 at 13:11)</a>:</h4>
<p>I think we're on the same page up to whether we should have a good impl in std. I personally don't think it's necessary, I would be in favor of deprecating the existing impl (and maybe replacing it with a relatively unperformant one, just to fix bugs, though I'm not even sure about doing that).</p>



<a name="190387471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190387471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190387471">(Mar 12 2020 at 13:13)</a>:</h4>
<p>I basically don't think a patchwork fix is going to cut it for std, no one knows the channel impl in std well enough, and that means a wholesale replacement, and I personally don't think channels are important enough to be in std for us to motivate seeking out a good implementation and such, especially as there's quite a few different knobs to tune</p>



<a name="190387493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190387493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190387493">(Mar 12 2020 at 13:14)</a>:</h4>
<p>I would find references to rng, serialization, etc. more compelling if channels weren't already in std; but they are, so I think providing a rock solid definitely-correct-&amp;-sound implementation is valuable</p>



<a name="190387561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190387561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190387561">(Mar 12 2020 at 13:14)</a>:</h4>
<p>(and by rock solid I don't necessarily mean competitive with crossbeam in terms of perf)</p>



<a name="190387621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190387621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190387621">(Mar 12 2020 at 13:15)</a>:</h4>
<p>I personally don't consider current inclusion to be meaningful -- it is mostly because in the (distant) past channels were considered "the" primitive for concurrency in Rust. These days, that's definitely not true I think.</p>



<a name="190387642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190387642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190387642">(Mar 12 2020 at 13:15)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> sorry, just to clarify, i'm not suggesting we do a patchwork thing here.</p>



<a name="190388059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190388059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190388059">(Mar 12 2020 at 13:20)</a>:</h4>
<p>Ah. Okay. Then I agree we are on the same page about the options, though I think that the right path forward is a deprecation without in-std replacement. I'm not sure if you agree.</p>



<a name="190388116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190388116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190388116">(Mar 12 2020 at 13:21)</a>:</h4>
<p>(good replacement that is, which would be competitive performance wise)</p>



<a name="190388262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190388262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190388262">(Mar 12 2020 at 13:22)</a>:</h4>
<p>yeah, that's where i lean.</p>



<a name="190406479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190406479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190406479">(Mar 12 2020 at 15:54)</a>:</h4>
<p>I think it flies in the face of our stability message and our "concurrency made easy" message if a stable module in the standard library is deprecated and people are told to just go scrounge through <a href="http://crates.io" target="_blank" title="http://crates.io">crates.io</a> for the current best crate (which is probably an unstable crate).</p>



<a name="190408792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190408792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190408792">(Mar 12 2020 at 16:10)</a>:</h4>
<p>I would definitely at this point say that the right API for channels is still somewhat of an open question, so adding another API to std would feel premature. Whether we deprecate std mpsc or not after replacing the innards with a slowish impl is a hard question, I agree. I would suspect that having it not be deprecated implies that it's the right thing to reach for though which is never going to be true in the short term at least.</p>
<p>I also think if we just don't have a good implementation that's 1.0 in the ecosystem maybe that's something to acknowledge and deprecating the std module may drive people to innovate (otherwise, you're competing with std... and likely winning in some sense, but still a bit unfortunate).</p>



<a name="190412999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190412999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190412999">(Mar 12 2020 at 16:43)</a>:</h4>
<p>Why should we replace mpsc with a slow implementation? Is it just because of the maintenance burden? If that's the only concern then we could do the same thing we did with <code>hashbrown</code>: <code>std</code> would add <code>crossbeam-channel</code> as a dependency and <code>mpsc</code> would be a wrapper around it.</p>



<a name="190413129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190413129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190413129">(Mar 12 2020 at 16:44)</a>:</h4>
<p>Deprecating mpsc is a separate decision. I don't think we should mix the two together.</p>



<a name="190416427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190416427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190416427">(Mar 12 2020 at 17:08)</a>:</h4>
<p>Well if we deprecate then a slow and simple impl means let code to vet, meaning we can be more confident in the soundness, etc.</p>



<a name="190417896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190417896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190417896">(Mar 12 2020 at 17:22)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> because the current implementation is broken in subtle ways</p>



<a name="190417936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190417936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190417936">(Mar 12 2020 at 17:22)</a>:</h4>
<p>(no known soundness holes, but deadlocks and panics are definitely known, if not easily reproducible)</p>



<a name="190418215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190418215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190418215">(Mar 12 2020 at 17:24)</a>:</h4>
<p>I'd prefer replacing the implementation with a wrapper around <code>crossbeam-channel</code>. It would avoid any issues in case someone is relying on the performance of <code>mpsc</code>.</p>



<a name="190418487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190418487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190418487">(Mar 12 2020 at 17:26)</a>:</h4>
<p>I'm not so sure that a compromise between both positions is necessary. <code>std</code>'s <code>mpsc</code> is not particularly fast and from what I can see; trivial implementations can outpace it without much work. I'm sure there are corner cases that need smoothing that I've not considered, but I've not found anything insummountable so far.</p>



<a name="190418725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190418725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190418725">(Mar 12 2020 at 17:28)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> if wrapping crossbeam-channel (or another, perhaps safer, crate) is viable, then that seems like a good path forward to me. My main worry there is that we may not have time to invest in reviewing the (new) implementation.</p>
<p>I believe <span class="user-mention" data-user-id="126931">@centril</span> at least has historically been against wrapping crossbeam's channels directly, but I don't know that we have good reasons not to do so.</p>



<a name="190419004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190419004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190419004">(Mar 12 2020 at 17:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/219381-t-libs/topic/Replacing.20mpsc/near/190418725" title="#narrow/stream/219381-t-libs/topic/Replacing.20mpsc/near/190418725">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> if wrapping crossbeam-channel (or another, perhaps safer, crate) is viable, then that seems like a good path forward to me. My main worry there is that we may not have time to invest in reviewing the (new) implementation.</p>
<p>I believe <span class="user-mention silent" data-user-id="126931">centril</span> at least has historically been against wrapping crossbeam's channels directly, but I don't know that we have good reasons not to do so.</p>
</blockquote>
<p>I don't know that I have had thoughts about this really. But the point made earlier in this topic about crossbeam's use of unsafe is apt. See e.g, <a href="https://github.com/crossbeam-rs/crossbeam/issues/315" target="_blank" title="https://github.com/crossbeam-rs/crossbeam/issues/315">https://github.com/crossbeam-rs/crossbeam/issues/315</a>, its use of memoffset, etc. for problematic cases.</p>



<a name="190419129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190419129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190419129">(Mar 12 2020 at 17:31)</a>:</h4>
<p>So if we wrap it, then I think crossbeam needs to go though reviews, and add appropriate <code>// SAFETY:</code> rationales</p>



<a name="190421697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190421697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190421697">(Mar 12 2020 at 17:49)</a>:</h4>
<p>I just checked crossbeam-channel and it doesn't seem to support <code>#[no_std]</code>, which would be a requirement for including it as a dependency of <code>std</code>. As such maybe we should consider <code>flume</code> instead (which has a very simple &amp; easy to review implementation).</p>



<a name="190421850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190421850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190421850">(Mar 12 2020 at 17:50)</a>:</h4>
<p>Ah nevermind, we can't use an external crate as a dependency due to the use of <code>Instant</code> in the <code>mpsc</code> API. This is the same issue that <code>parking_lot</code> encountered.</p>



<a name="190422264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190422264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190422264">(Mar 12 2020 at 17:53)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> can you tl;dr the Instant problem?</p>



<a name="190422394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190422394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190422394">(Mar 12 2020 at 17:54)</a>:</h4>
<p><code>Instant</code> is defined in libstd. So libstd can't depend on a crate that uses <code>Instant</code> since that would lead to a circular dependency.</p>



<a name="190422470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190422470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190422470">(Mar 12 2020 at 17:54)</a>:</h4>
<p>Basically crates that libstd depends on (<code>hashbrown</code>, <code>backtrace</code>, etc) must be <code>#[no_std} + alloc</code>.</p>



<a name="190422610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190422610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190422610">(Mar 12 2020 at 17:55)</a>:</h4>
<p>The plan with <code>parking_lot</code> was to use a submodule which is injected directly in the libstd crate. It would be similar to the way <code>stdarch</code> is included in <code>libcore</code>.</p>



<a name="190423146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190423146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190423146">(Mar 12 2020 at 17:58)</a>:</h4>
<p>Ah, that's hacky, but it seems like it would work :D</p>



<a name="190429034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190429034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190429034">(Mar 12 2020 at 18:48)</a>:</h4>
<p>flume is fairly small. we could just copy it.</p>



<a name="190467249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190467249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190467249">(Mar 13 2020 at 03:12)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> I just tested the <code>0.3.1</code> release of <code>flume</code> in <code>tokei</code>. I didn't notice any speed bumps compared to crossbeam, but it wasn't  really slower either, which I think is pretty positive considering it's relatively new implementation. I've pasted the hyperfine test results below.</p>
<ul>
<li><code>target/release/tokei</code> — built with flume</li>
<li><code>tokei</code> — Current released version</li>
</ul>
<h3>Rust Repo (93102 files)</h3>
<div class="codehilite"><pre><span></span><span class="go">Benchmark #1: target/release/tokei ../rust</span>
<span class="go">  Time (mean ± σ):      3.410 s ±  0.113 s    [User: 11.471 s, System: 5.096 s]</span>
<span class="go">  Range (min … max):    3.253 s …  3.676 s    10 runs</span>

<span class="go">Benchmark #2: tokei ../rust</span>
<span class="go">  Time (mean ± σ):      3.286 s ±  0.260 s    [User: 10.967 s, System: 5.305 s]</span>
<span class="go">  Range (min … max):    2.882 s …  3.676 s    10 runs</span>

<span class="go">Summary</span>
<span class="go">  &#39;tokei ../rust&#39; ran</span>
<span class="go">    1.04 ± 0.09 times faster than &#39;target/release/tokei ../rust&#39;</span>
</pre></div>


<h3>UnrealEngine (117857 files)</h3>
<div class="codehilite"><pre><span></span><span class="go">Benchmark #1: target/release/tokei ../../UnrealEngine</span>
<span class="go">  Time (mean ± σ):      5.453 s ±  0.167 s    [User: 22.769 s, System: 6.960 s]</span>
<span class="go">  Range (min … max):    5.157 s …  5.679 s    10 runs</span>

<span class="go">Benchmark #2: tokei ../../UnrealEngine</span>
<span class="go">  Time (mean ± σ):      5.078 s ±  0.224 s    [User: 21.323 s, System: 6.965 s]</span>
<span class="go">  Range (min … max):    4.883 s …  5.615 s    10 runs</span>

<span class="go">Summary</span>
<span class="go">  &#39;tokei ../../UnrealEngine&#39; ran</span>
<span class="go">    1.07 ± 0.06 times faster than &#39;target/release/tokei ../../UnrealEngine&#39;</span>
</pre></div>



<a name="190484283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190484283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190484283">(Mar 13 2020 at 09:22)</a>:</h4>
<p><span class="user-mention" data-user-id="219696">@XAMPPRocky</span> That's good news! Any chance you could get a similar benchmark with std's mpsc? It seems that std's is extremely good at single use one-shot channels and rapid channel construction. From what I can see flume improves upon crossbeam a lot for such use-cases, but it's still the use-case that flume seems to fall behind std in.</p>
<p>I've not focussed too much on this use-case yet since I feel that it's a forgivable issue when compared to speed improvements elsewhere and is unlikely to be a bottleneck (who in their right mind is creating millions of queues per second?!) but I think there's more I can do on this front regardless.</p>



<a name="190488572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190488572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190488572">(Mar 13 2020 at 10:26)</a>:</h4>
<p>I've gone over Flume's code, fully documenting everything.</p>



<a name="190590889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190590889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190590889">(Mar 14 2020 at 10:18)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> Hmm, testing <code>std::mpsc</code> gives similar performance, I remember when I originally added <code>crossbeam</code> it was a noticable speed bump, but it seems like the channels aren't any kind of bottleneck anymore in tokei.</p>



<a name="190621052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190621052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190621052">(Mar 15 2020 at 00:00)</a>:</h4>
<p>I've just added experimental support for bounded queues, as well as implementing <code>Sync</code> for <code>Sender</code>s (I previously didn't permit sharing senders since I was not certain that it was possible, but I've now confirmed that it is). Contrary to my expectations, it didn't have as much of an impact on performance as I initially imagined. As far as I can tell, this puts <code>flume</code> at feature parity with <code>std</code>'s <code>mpsc</code>.</p>



<a name="190656561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190656561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190656561">(Mar 15 2020 at 17:11)</a>:</h4>
<p>Bounded queue support is now properly working and is in the latest release.</p>



<a name="190878192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/190878192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#190878192">(Mar 17 2020 at 16:52)</a>:</h4>
<p>I've also added experimental support for a <code>select!</code>-like interface. It supports sending and receiving.</p>



<a name="191243674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/191243674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#191243674">(Mar 20 2020 at 13:42)</a>:</h4>
<p><span class="user-mention" data-user-id="222471">@BurntSushi</span> Do you have any thoughts on <code>async</code> support being in <code>std</code>'s mpscs? It's being added to <code>flume</code> and it turns out that the implementation is pretty trivial.</p>



<a name="191244158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/191244158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Restioson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#191244158">(Mar 20 2020 at 13:47)</a>:</h4>
<p>hi! on this subject, the other options would be 1. remove it from whatever version of flume gets into std or 2. do 1, but also use async flume to replace futures's channels (from my small tests it is a lot faster)</p>



<a name="191348577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/191348577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Restioson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#191348577">(Mar 21 2020 at 14:36)</a>:</h4>
<p>update on flume - catching up to crossbeam on windows and linux now in many benches in some branches</p>



<a name="191405856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/191405856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#191405856">(Mar 22 2020 at 17:11)</a>:</h4>
<p><span class="user-mention" data-user-id="222471">@BurntSushi</span> Did you happen to have that benchmark you did for Reddit hanging around? We've spent the last week optimising Flume and I was wondering if we could run it up against the latest version.</p>



<a name="191406431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/191406431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#191406431">(Mar 22 2020 at 17:23)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> which benchmark? can you share the reddit link?</p>



<a name="191407264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/191407264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#191407264">(Mar 22 2020 at 17:43)</a>:</h4>
<p>Apologies, I managed to get you confused with <span class="user-mention" data-user-id="128448">@stjepang</span> .</p>



<a name="191411334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/191411334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#191411334">(Mar 22 2020 at 19:12)</a>:</h4>
<p>I've now run the benchmarks, results are here: <a href="https://github.com/crossbeam-rs/crossbeam/pull/481" target="_blank" title="https://github.com/crossbeam-rs/crossbeam/pull/481">https://github.com/crossbeam-rs/crossbeam/pull/481</a></p>



<a name="191550908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/191550908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#191550908">(Mar 23 2020 at 23:24)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/70340" target="_blank" title="https://github.com/rust-lang/rust/issues/70340">https://github.com/rust-lang/rust/issues/70340</a> (just dropping here...)</p>



<a name="196715972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196715972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196715972">(May 07 2020 at 00:46)</a>:</h4>
<p>I've been doing some work recently on the <code>flavour-refactor</code> branch of Flume (<a href="https://github.com/zesterer/flume/tree/flavour-refactor" title="https://github.com/zesterer/flume/tree/flavour-refactor">https://github.com/zesterer/flume/tree/flavour-refactor</a>). It massively simplifies a lot of the internals and fixes all existing issues that I'm aware of (expanding the test suite too). It's not merged to <code>master</code> yet owning to the fact that is lacks <code>async</code> and <code>select</code> support at the moment, but I'm fairly happy with the implementation regarding features that would be needed for it to replace <code>std::sync::mpsc</code>. It brings a lot of very useful features to Flume:</p>
<ul>
<li><code>Sender</code> and <code>Receiver</code> are both <code>Sync + Send</code></li>
<li>MPMC is now supported (i.e: you can clone a <code>Receiver</code>)</li>
<li><code>send_timeout</code>/<code>send_deadline</code></li>
<li>Rendezvous channels are now working great</li>
</ul>
<p>As far as I'm aware, this addresses all of the wishlist items in <span class="user-mention" data-user-id="128448">@stjepang</span> 's 'New Channels' proposal that can be found here: <a href="https://stjepang.github.io/2019/03/02/new-channels.html" title="https://stjepang.github.io/2019/03/02/new-channels.html">https://stjepang.github.io/2019/03/02/new-channels.html</a></p>
<p>It's also performing pretty well on benchmarks (both our now fairly extensive benchmark suite, and <code>crossbeam-channel</code>'s benchmarks). I think there's still more that can be done with the performance of rendezvous and low-bound channels (something I'd love to talk with <span class="user-mention" data-user-id="128448">@stjepang</span> about), but it's at least beating <code>std::sync::mpsc</code> on every benchmark with at least a ~50% margin (and by much, much more on most).</p>
<p>This implementation isn't "ready" yet (I still need to adjust some things to make sure it performs similarly on non-POSIX platforms) but I'd say that it's in a good state for an initial review, should anybody be interested.</p>



<a name="196750960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196750960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> stjepang <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196750960">(May 07 2020 at 10:20)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> Great work! :) Btw, crossbeam-channel has a very extensive test suite (380 tests total!). I suggest stealing those and porting to flume to make sure the codebase is correct (it shouldn't be too much work, it's mostly copy-paste). Some of those tests are from the standard library and some are from the Go codebase. If you pass those tests (and use <code>SeqCst</code> whenever in doubt about memory orderings), you can be 99.99% confident flume is correct. </p>
<p>Regarding performance, it seems channels with large capacity are plenty fast already and only low-capacity channels are left to improve. I think what could help is to expose <code>head</code> and <code>tail</code> (<code>AtomicUsize</code>s) outside the main channel mutex. That way, send/receive operation can check whether they can make progress or not without locking any mutexes. So perhaps you could restructure channels as follows:</p>
<div class="codehilite"><pre><span></span><code><span class="n">head</span>: <span class="nc">AtomicUsize</span><span class="p">,</span><span class="w"></span>
<span class="n">tail</span>: <span class="nc">AtomicUsize</span><span class="p">,</span><span class="w"></span>
<span class="n">buffer</span>: <span class="nc">Mutex</span><span class="o">&lt;</span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="n">sig_depot</span>: <span class="nc">Depot</span><span class="p">,</span><span class="w"></span>
</code></pre></div>



<a name="196790498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196790498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196790498">(May 07 2020 at 15:47)</a>:</h4>
<p>Thanks for the advice! I might try special-casing channels under a certain capacity in the hope of gaining some performance wins.</p>
<p>I just ported all of the <code>crossbeam-channel</code> tests (with the exception of those that required <code>select!</code> since I've not yet reimplemented it). The tests caught a few minor bugs that I'd missed during refactoring (forgetting to rename error variants, etc.), but otherwise everything passes, so that's nice.</p>



<a name="196798080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196798080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196798080">(May 07 2020 at 16:45)</a>:</h4>
<p>If possible, try running that on an an architecture with weaker memory ordering too</p>



<a name="196800739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196800739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196800739">(May 07 2020 at 17:04)</a>:</h4>
<p>if someone can point me at a specific repo to just clone and "cargo test" i can run it on my raspberry pi, i'm told that ARM has a weaker memory ordering than the Intel chips.</p>



<a name="196804708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196804708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196804708">(May 07 2020 at 17:34)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> <code>git clone git@github.com:zesterer/flume.git &amp;&amp; git checkout flavour-refactor &amp;&amp; cargo test</code></p>



<a name="196849478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196849478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196849478">(May 08 2020 at 01:17)</a>:</h4>
<p>I just went to try that on a big POWER9 (128 cpus), but there are a bunch of compilation errors</p>



<a name="196849502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196849502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196849502">(May 08 2020 at 01:17)</a>:</h4>
<p>unknown fields, methods not found -- seems to be in a bad state</p>



<a name="196875664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196875664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196875664">(May 08 2020 at 09:49)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> Could you send a pastebin of the errors you found?</p>



<a name="196919768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196919768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196919768">(May 08 2020 at 16:46)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> <a href="https://gist.github.com/cuviper/3ebd0330d11fe0867a2f919282003b07" title="https://gist.github.com/cuviper/3ebd0330d11fe0867a2f919282003b07">https://gist.github.com/cuviper/3ebd0330d11fe0867a2f919282003b07</a></p>



<a name="196924587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196924587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196924587">(May 08 2020 at 17:22)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> Oh, apologies. I forgot to mention that you'll need to build with <code>--no-default-features</code> to disable <code>select</code> and <code>async</code> support (neither of which are working right now)</p>



<a name="196925226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196925226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196925226">(May 08 2020 at 17:27)</a>:</h4>
<p>OK, then <code>tests/zero.rs</code> complains that it can't find <code>rand</code></p>



<a name="196925267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196925267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196925267">(May 08 2020 at 17:27)</a>:</h4>
<p>also:</p>
<div class="codehilite"><pre><span></span><code>error[E0507]: cannot move out of a shared reference
   --&gt; tests/iter.rs:108:20
    |
108 |     let mut iter = (&amp;r).into_iter();
    |                    ^^^^ move occurs because value has type `flume::Receiver&lt;i32&gt;`, which does not implement the `Copy` trait
</code></pre></div>



<a name="196931153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196931153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196931153">(May 08 2020 at 18:14)</a>:</h4>
<p>I'm still interested but my ISP died (posting from my phone) so that put git cloning anything on hold</p>



<a name="196934407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196934407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196934407">(May 08 2020 at 18:43)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> My bad, I forgot to commit the very latest changes. Schoolboy error on my part. It should work now!</p>



<a name="196934986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196934986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196934986">(May 08 2020 at 18:47)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> OK, that built, but it's currently stuck on:</p>
<div class="codehilite"><pre><span></span><code>test hydra ... test hydra has been running for over 60 seconds
</code></pre></div>



<a name="196936708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196936708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196936708">(May 08 2020 at 19:01)</a>:</h4>
<p>oh now it's done</p>



<a name="196936715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196936715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196936715">(May 08 2020 at 19:01)</a>:</h4>
<p>all passed</p>



<a name="196951899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196951899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196951899">(May 08 2020 at 21:19)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> FWIW I ran <code>hydra</code> again to time it:</p>
<ul>
<li>debug: <code>1316.53user 334.04system 7:16.05elapsed 378%CPU</code></li>
<li>release: <code>682.85user 435.12system 2:06.66elapsed 882%CPU</code></li>
</ul>



<a name="196952023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196952023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196952023">(May 08 2020 at 21:20)</a>:</h4>
<p>maybe that's to be expected, I don't know...</p>



<a name="196964345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196964345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196964345">(May 09 2020 at 00:22)</a>:</h4>
<p>Great to hear that it works! <code>hydra</code> is expected to take some time: I was using it as a poor man's fuzzing test for spurious race issues early in development.</p>



<a name="196980574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196980574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196980574">(May 09 2020 at 08:29)</a>:</h4>
<blockquote>
<p>Safe: No unsafe code anywhere in the codebase!</p>
</blockquote>
<p>Wait what? I naively thought it would be impossible to implement a concurrent data structure entirely in safe code, what is this magic?^^</p>



<a name="196981927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196981927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196981927">(May 09 2020 at 09:11)</a>:</h4>
<p>Like, somehow this has to arrange ownership transfer across threads, and the compiler cannot possibly understand that you did all the synchronization required for this when you use atomics yourself... I must be missing something.</p>



<a name="196981933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196981933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196981933">(May 09 2020 at 09:11)</a>:</h4>
<p>oh I see, you are using <code>Mutex</code> and friends from std. that makes sense.</p>



<a name="196981936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196981936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196981936">(May 09 2020 at 09:11)</a>:</h4>
<p>now I am surprised that this can be fast :D</p>



<a name="196985639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196985639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196985639">(May 09 2020 at 10:53)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I was quite surprised myself that I could manage to get things running this fast. Based on my experimentation so far, it seems that reducing contention is a far more important factor than implementing a lock-free algorithm. Right now, we do this with simple backoff spinning and yielding which seems to perform well on most platforms.</p>



<a name="196985690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196985690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196985690">(May 09 2020 at 10:54)</a>:</h4>
<p>impressive</p>



<a name="196985703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196985703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196985703">(May 09 2020 at 10:54)</a>:</h4>
<p>on which host OS did you measure? also did you compare with using parking_lot <code>Mutex</code> instead?</p>



<a name="196985720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196985720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196985720">(May 09 2020 at 10:55)</a>:</h4>
<p>ah you mentioned non-POSIX still has perf issues</p>



<a name="196985785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196985785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196985785">(May 09 2020 at 10:56)</a>:</h4>
<p>Swapping out <code>spin::Mutex</code> and backoff with plain old <code>std::sync::Mutex</code> on Windows seems to recooperate similar performance gains. I don't personally run Windows, but <span class="user-mention" data-user-id="274649">@Restioson</span> does.</p>



<a name="196987859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196987859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Restioson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196987859">(May 09 2020 at 11:47)</a>:</h4>
<p>Can test windows again probably today or tomorrow</p>



<a name="196988118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196988118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196988118">(May 09 2020 at 11:53)</a>:</h4>
<p>oh you are using <code>spin</code>? that's where the unsafe code is then :D<br>
that crate <a href="https://github.com/mvdnes/spin-rs" title="https://github.com/mvdnes/spin-rs">is unmaintained</a> unfortunately</p>



<a name="196988185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196988185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196988185">(May 09 2020 at 11:54)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> Indeed. We only use <code>spin::Mutex</code> which is pretty much just a sample CAS and is trivially sound though. I might just copy the code and bring it into the repo in time.</p>



<a name="196988312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196988312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196988312">(May 09 2020 at 11:57)</a>:</h4>
<p>might be worth trying <code>parking_lot::Mutex</code> first</p>



<a name="196988314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196988314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196988314">(May 09 2020 at 11:57)</a>:</h4>
<p>to avoid local unsafe code :D</p>



<a name="196988800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196988800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196988800">(May 09 2020 at 12:11)</a>:</h4>
<p>Perhaps, although that might hinder attempts to have Flume be included in <code>std</code> (since I believe there are several obstacles preventing <code>parking_lot</code> in <code>std</code>). I did some benchmarks earlier in development with <code>parking_lot</code>, and I found about a 30% performance improvement across the board.</p>



<a name="196992207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196992207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196992207">(May 09 2020 at 13:41)</a>:</h4>
<p>there are many obstacles to using parking_lot for <code>std::Mutex</code> etc... I am not sure how many of those also apply to just using it internally in some lib</p>



<a name="196994383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/196994383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#196994383">(May 09 2020 at 14:33)</a>:</h4>
<p>if we're able to pull it into std and willing to use it, I think we'd probably be at the point where we'd use it for std::Mutex</p>



<a name="197011941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/197011941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#197011941">(May 09 2020 at 20:43)</a>:</h4>
<p>What <em>is</em> blocking the use of <code>parking_lot</code> in std?</p>



<a name="197012141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/197012141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#197012141">(May 09 2020 at 20:48)</a>:</h4>
<p>There were concerns that parking_lot didn't have enough tests.</p>



<a name="197012164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/197012164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#197012164">(May 09 2020 at 20:49)</a>:</h4>
<p>Alex did a pretty thorough review: <a href="https://github.com/faern/parking_lot/pull/1" title="https://github.com/faern/parking_lot/pull/1">https://github.com/faern/parking_lot/pull/1</a></p>



<a name="212407919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212407919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212407919">(Oct 06 2020 at 10:19)</a>:</h4>
<p>We've been doing quite a bit of work on Flume recently. We're now a few more releases down the line and the code is now quite rugged and feature-filled. All of the old constraints are gone (<code>Sender</code>/<code>Receiver</code> are both <code>Clone + Send + Sync</code> now) and several new APIs are now available (<code>is_empty</code>, <code>is_disconnected</code>, etc.). <code>async</code> support is now fairly mature (it's being used in an asynchronous context in a large codebase developed by the company I work for). What  approach would be needed if I wanted to push for inclusion of Flume in <code>std</code>? Is it worth forking Rust and opening a draft PR?</p>



<a name="212415814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212415814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212415814">(Oct 06 2020 at 11:52)</a>:</h4>
<p><span class="user-mention" data-user-id="250715">@Joshua Barretto</span> That’s super exciting! I think there are a couple avenues open. To get the source into std I think we could:</p>
<ul>
<li>Inline and replace the existing implementation of <code>mpsc</code>.</li>
<li>Look at pulling <code>flume</code> into <code>rust-lang</code> and adding it as a dependency so mpsc can use it (I think this might be my personal preference if the API has expanded, but might also depend on whether <code>flume</code> has dependencies of its own and is no-std. <span class="user-mention" data-user-id="143274">@Amanieu</span> might have better thoughts from experience with <code>hashbrown</code>)</li>
</ul>
<p>I think for either of these cases we’ll want to run through a thorough review of <code>flume</code> itself.</p>
<p>If we want to offer a better API than <code>std::sync::mpsc</code> in the future we could look at reviving the <code>std::channel</code> proposal which would fit nicely into the “break up <code>std::sync</code>” story.</p>



<a name="212416463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212416463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212416463">(Oct 06 2020 at 11:58)</a>:</h4>
<p>Hello! To address your points:</p>
<ul>
<li>
<p>One of the (personal) aims I've had for <code>flume</code> is to fulfill the channel proposal that Stjepang proposed some time ago. Although the blog post doesn't seem to be publicly available any longer (perhaps it was moved?) I believe that <code>flume</code> currently addresses all of the points mentioned in the post. In this regard, I think it would be a shame not to aim for the <code>std::channel</code> proposal.</p>
</li>
<li>
<p>Having <code>flume</code> be a dependency of <code>std</code> would be the ideal option but unfortunately it would likely be blocked by the fact that <code>flume</code> depends on <code>std</code>'s thread parking. That said, the thread parking has been deliberately decoupled from the main channel impl (which should only depend on <code>core</code>) so it should be possible to reach a compromise whereby <code>std</code> depends on <code>flume</code>, but has a small amount of glue code to tell <code>flume</code> how to park threads (trivial for the compiler to inline, of course).</p>
</li>
</ul>



<a name="212418301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212418301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212418301">(Oct 06 2020 at 12:15)</a>:</h4>
<p>I’m sure we could cook something up 🙂 Some libraries have a crate feature that’s used when they’re a dependency of <code>std</code>. How would you feel about possibly moving <code>flume</code> into <code>rust-lang</code> if we wanted to pull it in?</p>



<a name="212421832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212421832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212421832">(Oct 06 2020 at 12:46)</a>:</h4>
<p>I'm not completely adverse to such a thing. No doubt being a member of <code>rust-lang</code> would make it more 'immune' to maintainer disappearance. That said, with a stable Rust job and a lot of projects written in the language, I've got absolutely no intention of departing from the Rust ecosystem any time in the near future. I also feel that several of <code>flume</code>'s features are things that we might not initially want to stabilise and I'd be adverse to having the codebase split in such a manner (for example, <code>flume</code> has select, async and fairness support, all behind feature flags).</p>



<a name="212424056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212424056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212424056">(Oct 06 2020 at 13:04)</a>:</h4>
<p>i think my position is still something like this:</p>
<ul>
<li>Either deprecate mpsc or keep its API the same and replace it with a simpler implementation from flume. Possibly even by just copying code. I imagine that only implementing the mpsc API would permit some simplifications.</li>
<li>Keep flume outside of std for now. i'd like to see it bake in the ecosystem before even considering it for std personally. its API looks very similar to crossbeam-channel (sans async), but without the nice <code>select!</code> macro. so to me, it seems like there is some healthy competition there, and i don't really see a reason to bless one over the other. (which is maybe an argument for keeping it out of the rust-lang org too.)</li>
</ul>



<a name="212452673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212452673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Barretto <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212452673">(Oct 06 2020 at 16:29)</a>:</h4>
<p>That makes sense. In your view, what would constitute sufficient maturity for this to be taken to the next stage?</p>



<a name="212459678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212459678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212459678">(Oct 06 2020 at 17:32)</a>:</h4>
<p>it's hard to quantify it precisely, but some combination of "widespread adoption" and "stability over a period of time" maybe? basically, some kind of evidence that a mass of people are happy with its API and implementation. given the API similarity between it and crossbeam-channel, there's probably an argument that could be made that the API at least has been partially proved out. but there are differences: flume has a non-macro select and has async APIs. are those the right choices? i'm not sure.</p>



<a name="212611758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212611758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212611758">(Oct 07 2020 at 20:01)</a>:</h4>
<p>What about having a official blessed channel library in <code>rust-lang</code> and point the deprecation message<br>
of <code>mpsc</code> to e.g. <code>flume</code> as a compromis.</p>
<p>I remember that a few years back the consensus was that it was a mistake to place <code>mpsc</code> in <code>std</code> as there are to many different ways to do channels with to different nonces which are useful for different contexts, I think.</p>
<p>But then I guess this (the consensus)  might very likely have changed since then.</p>
<p>Having better channels in <code>std</code> wouldn't be bad, but then having a "blessed" 3rd party library would be as good for me.</p>
<p>What I think is important that everyone looking for channels will fastely  find  a channel library which they don't need to review as it's not from a arbitrary 3rd party but a trust source (e.g. rust-lang github org).</p>



<a name="212612790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212612790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212612790">(Oct 07 2020 at 20:08)</a>:</h4>
<p>I think one think which makes me favor having it as a independent crate in <code>rust-lang</code> and having doc references to it from std is that it has some neat features we would have to drop elsewise:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="p">[</span><span class="n">features</span><span class="p">]</span><span class="w"></span>
<span class="n">select</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[]</span><span class="w"></span>
<span class="k">async</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="s">"futures-sink"</span><span class="p">,</span><span class="w"> </span><span class="s">"futures-core"</span><span class="p">]</span><span class="w"></span>
<span class="n">eventual</span><span class="o">-</span><span class="n">fairness</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="s">"async"</span><span class="p">,</span><span class="w"> </span><span class="s">"nanorand"</span><span class="p">]</span><span class="w"></span>
<span class="n">default</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="s">"async"</span><span class="p">,</span><span class="w"> </span><span class="s">"select"</span><span class="p">,</span><span class="w"> </span><span class="s">"eventual-fairness"</span><span class="p">]</span><span class="w"></span>
</code></pre></div>

<p>Because lets be honest <code>futures</code> isn't ready or meant to be pulled into <code>std</code> and even through it originally was meant to be the standard library for handling futures it kinda didn't play out that way has has become somewhat messy and many libraries now depend on things like <code>futures-lite</code> or role their own ad-hoc async/await based combinators.</p>



<a name="212615473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212615473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212615473">(Oct 07 2020 at 20:32)</a>:</h4>
<p><span class="user-mention" data-user-id="209646">@Philipp Korber</span> that was mentioned. and why are we going to play favorites and bless flume by moving it into rust-lang when there is also crossbeam-channel? are there meaningful differences there?</p>



<a name="212615616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212615616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212615616">(Oct 07 2020 at 20:34)</a>:</h4>
<p>I just think it is important to have one or multiple well trusted channel libraries .</p>



<a name="212615627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212615627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212615627">(Oct 07 2020 at 20:34)</a>:</h4>
<p>Or channels in <code>std</code>.</p>



<a name="212616421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212616421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212616421">(Oct 07 2020 at 20:41)</a>:</h4>
<p>I would prefer not to link to any particular (not-owned-by-<code>rust-lang</code>-org) crate from the standard library documentation.  A category might be fine, though.  (I just don't want to do anything to encourage people to send PRs linking to their crates from std, or to <code>Itertools</code> from <code>Iterator</code>, or ...)</p>



<a name="212616590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212616590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212616590">(Oct 07 2020 at 20:43)</a>:</h4>
<p>but that's something that almost nobody will disagree with. it doesn't really move us forward. "i think it's important to have one or multiple well trusted random number libraries" is likely also something a lot of people would agree with. but <code>rand</code> is not in rust-lang and AFAIK there is no push to move it there.</p>
<p>if flume was the only game in town, that might be one thing. but <code>crossbeam-channel</code>, IMO, satisfies the "well trusted" crtierion already. why should we going to play favorites and pick one over the other? i'm not saying we shouldn't or can't, but i'd like a good reason to do it.</p>



<a name="212616741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20mpsc/near/212616741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20mpsc.html#212616741">(Oct 07 2020 at 20:44)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> i believe that is our currently policy, although there have been some references to external crates that have slipped through the cracks. i do think it would be nice to link to external crates from std docs, but don't have the resources to champion that effort. (because any such policy would have to of course carefully address very valid concerns like yours.)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>